﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ComObjType - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The ComObjType function retrieves type information from a COM object." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>ComObjType</h1>

<p>Retrieves type information from a COM object.</p>

<pre class="Syntax">VarType := <span class="func">ComObjType</span>(ComObject)
IName   := <span class="func">ComObjType</span>(ComObject, "Name")
IID     := <span class="func">ComObjType</span>(ComObject, "IID")
CName   := <span class="func">ComObjType</span>(ComObject, "Class")
CLSID   := <span class="func">ComObjType</span>(ComObject, "CLSID")
</pre>

<h2 id="Parameters">参数</h2>
<dl>

  <dt>ComObject</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#objects">对象</a></p>
    <p>A wrapper object containing a COM object or typed value.</p>
  </dd>

  <dt>Param2</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>The second parameter is a string indicating the type information to retrieve.</p>
  </dd>

</dl>

<h2 id="Return_Value">返回值</h2>
<p>The return value depends on the value of <em>Param2</em>:</p>
<table class="info">
  <tr>
    <th>Param2</th>
    <th style="white-space: nowrap">Return Type</th>
    <th>Return Value</th>
  </tr>
  <tr>
    <td>Omitted</td>
    <td><a href="../Concepts.htm#numbers">Integer</a></td>
    <td>A <a href="#vt">variant type code</a> which indicates the type of value contained by the COM wrapper object.</td>
  </tr>
  <tr>
    <td><code>"Name"</code></td>
    <td><a href="../Concepts.htm#strings">字符串</a></td>
    <td>The name of the object's default interface.</td>
  </tr>
  <tr>
    <td><code>"IID"</code></td>
    <td><a href="../Concepts.htm#strings">字符串</a></td>
    <td>The globally unique identifier (GUID) of the object's default interface.</td>
  </tr>
  <tr>
    <td><code>"Class"</code></td>
    <td><a href="../Concepts.htm#strings">字符串</a></td>
    <td>The object's class name. Note that this is not the same as a Prog ID (a Prog ID is a name used to identify the class in the system registry, or for ComObjCreate).</td>
  </tr>
  <tr>
    <td><code>"CLSID"</code></td>
    <td><a href="../Concepts.htm#strings">字符串</a></td>
    <td>The globally unique identifier (GUID) of the object's class. Classes are often registered by CLSID under the <code>HKCR\CLSID</code> registry key.</td>
  </tr>
</table>
<p>An empty string is returned if either parameter is invalid or if the requested type information could not be retrieved.</p>

<h2 id="vt">Variant(变体) 类型常量</h2>
<pre>
VT_EMPTY     :=      0  <em>; 未指定值</em>
VT_NULL      :=      1  <em>; 类似 SQL 中的空值</em>
VT_I2        :=      2  <em>; 16 位有符号整数</em>
VT_I4        :=      3  <em>; 32 位有符号整数</em>
VT_R4        :=      4  <em>; 32 位浮点数</em>
VT_R8        :=      5  <em>; 64 位浮点数</em>
VT_CY        :=      6  <em>; 货币</em>
VT_DATE      :=      7  <em>; 日期</em>
VT_BSTR      :=      8  <em>; COM 字符串(带长度前缀的 Unicode 字符串)</em>
VT_DISPATCH  :=      9  <em>; COM 对象</em>
VT_ERROR     :=    0xA  <em>; 错误码(32 位整数)</em>
VT_BOOL      :=    0xB  <em>; 布尔值: 真(-1) 或 假(0)</em>
VT_VARIANT   :=    0xC  <em>; <a href="http://msdn.microsoft.com/en-us/library/ms221627.aspx">VARIANT</a>(必须与 VT_ARRAY 或 VT_BYREF 组合使用)</em>
VT_UNKNOWN   :=    0xD  <em>; IUnknown 接口指针</em>
VT_DECIMAL   :=    0xE  <em>; 小数(不支持)</em>
VT_I1        :=   0x10  <em>; 8 位有符号整数</em>
VT_UI1       :=   0x11  <em>; 8 位无符号整数</em>
VT_UI2       :=   0x12  <em>; 16 位无符号整数</em>
VT_UI4       :=   0x13  <em>; 32 位无符号整数</em>
VT_I8        :=   0x14  <em>; 64 位有符号整数</em>
VT_UI8       :=   0x15  <em>; 64 位无符号整数</em>
VT_INT       :=   0x16  <em>; 有符号机器整数</em>
VT_UINT      :=   0x17  <em>; 无符号机器整数</em>
VT_RECORD    :=   0x24  <em>; 用户定义的类型 -- 不支持</em>
VT_ARRAY     := 0x2000  <em>; <a href="http://msdn.microsoft.com/en-us/library/ms221482.aspx">SAFEARRAY</a></em>
VT_BYREF     := 0x4000  <em>; 指向另一种类型值的指针</em>
<em>/*
 VT_ARRAY 和 VT_BYREF 与另一个值组合使用(使用按位或)
 以表示最终的类型. 例如, 0x2003 表示 32 位有符号整数的 <a href="http://msdn.microsoft.com/en-us/library/ms221482.aspx">SAFEARRAY</a>, 而 0x400C 表示指向 <a href="http://msdn.microsoft.com/en-us/library/ms221627.aspx">VARIANT</a> 的指针.
*/</em>
</pre>

<h2>General 备注</h2>
<p>In most common cases, return values from methods or properties of COM objects are converted to an appropriate data type supported by AutoHotkey. Types which aren't specifically handled are coerced to strings via <a href="http://msdn.microsoft.com/en-us/library/ms221258.aspx">VariantChangeType</a>; if this fails or if the variant type contains the VT_ARRAY or VT_BYREF flag, an object containing both the value and its type is returned instead.</p>
<p>For any variable <i>x</i>, if <code>ComObjType(x)</code> returns an integer, <i>x</i> contains a COM object wrapper.</p>
<p>If <em>Param2</em> is <code>"Name"</code> or <code>"IID"</code>, type information is retrieved via the <a href="https://msdn.microsoft.com/en-us/library/ms221571.aspx">IDispatch::GetTypeInfo</a> interface method. <em>ComObject</em>'s variant type must be VT_DISPATCH.</p>
<p>If <em>Param2</em> is <code>"Class"</code> or <code>"CLSID"</code>, type information is retrieved via the <a href="https://msdn.microsoft.com/en-us/library/ms690192.aspx">IProvideClassInfo::GetClassInfo</a> interface method. <em>ComObject</em>'s variant type must be VT_DISPATCH or VT_UNKNOWN, and the object must implement the IProvideClassInfo interface (some objects do not).</p>

<h2 id="Related">相关</h2>
<p><a href="ComObjValue.htm">ComObjValue</a>, <a href="ComObject.htm">ComObject</a>, <a href="ComObjCreate.htm">ComObjCreate</a>, <a href="ComObjGet.htm">ComObjGet</a>, <a href="ComObjActive.htm">ComObjActive</a></p>

<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>
d := <a href="ComObjCreate.htm">ComObjCreate</a>("Scripting.Dictionary")
MsgBox
(
    "Variant type:`t" ComObjType(d) "
    Interface name:`t" ComObjType(d, "Name") "
    Interface ID:`t" ComObjType(d, "IID") "
    Class name:`t" ComObjType(d, "Class") "
    Class ID (CLSID):`t" ComObjType(d, "CLSID")
)</pre>
</div>

</body>
</html>